package com.work.work.controller;

import com.work.work.common.R;
import com.work.work.dto.ProjectStatusStatDTO;
import com.work.work.dto.TaskProgressDTO;
import com.work.work.service.ProgressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "进度跟踪")
@RestController
@RequestMapping("/progress")
public class ProgressController {
    @Autowired
    private ProgressService progressService;

    @Operation(summary = "获取项目进度")
    @GetMapping("/project/{projectId}")
    public R<List<TaskProgressDTO>> getProjectProgress(@PathVariable Integer projectId) {
        return R.ok(progressService.getProjectProgress(projectId), "项目创建成功");
    }

    @Operation(summary = "获取任务进度")
    @GetMapping("/task/{taskId}")
    public R<TaskProgressDTO> getTaskProgress(@PathVariable Integer taskId) {
        TaskProgressDTO progress = progressService.getTaskProgress(taskId);
        return progress != null ? R.ok(progress, "项目创建成功") : R.fail("任务不存在");
    }

    @Operation(summary = "获取逾期任务")
    @GetMapping("/overdue")
    public R<List<TaskProgressDTO>> getOverdueTasks() {
        return R.ok(progressService.getOverdueTasks(), "项目创建成功");
    }

    @Operation(summary = "按状态获取任务")
    @GetMapping("/status/{status}")
    public R<List<TaskProgressDTO>> getTasksByStatus(@PathVariable Integer status) {
        return R.ok(progressService.getTasksByStatus(status), "项目创建成功");
    }


    @Operation(summary = "获取项目状态统计")
    @GetMapping("/project/stats")
    public R<List<ProjectStatusStatDTO>> getProjectStatusStats() {
        return R.ok(progressService.getProjectStatusStats(), "项目创建成功");
    }
}